public class DefaultRecordStore extends AbstractEvictableRecordStore
AbstractEvictableRecordStore.ReadOnlyRecordIterator
Modifier and Type | Field and Description |
---|---|
protected InMemoryFormat |
inMemoryFormat |
protected MapKeyLoader |
keyLoader |
protected Collection<Future> |
loadingFutures
A collection of futures representing pending completion of the key and
value loading tasks.
|
protected LockStore |
lockStore |
protected ILogger |
logger |
protected MapContainer |
mapContainer |
protected MapDataStore<Data,Object> |
mapDataStore |
protected MapServiceContext |
mapServiceContext |
protected MapStoreContext |
mapStoreContext |
protected RecordStoreMutationObserver<Record> |
mutationObserver |
protected String |
name |
protected int |
partitionId |
protected RecordFactory |
recordFactory |
protected com.hazelcast.map.impl.recordstore.RecordStoreLoader |
recordStoreLoader |
protected SerializationService |
serializationService |
protected LocalRecordStoreStatsImpl |
stats |
protected Storage<Data,Record> |
storage |
protected ValueComparator |
valueComparator |
clearExpiredRecordsTask, eventService, expirationIterator, expiredKeys, expiryDelayMillis, hasEntryWithCustomExpiration, mapEventPublisher, thisAddress
DEFAULT_MAX_IDLE, DEFAULT_TTL
Constructor and Description |
---|
DefaultRecordStore(MapContainer mapContainer,
int partitionId,
MapKeyLoader keyLoader,
ILogger logger) |
Modifier and Type | Method and Description |
---|---|
protected void |
addMapEntrySet(Map<Object,Object> entries,
MapEntries mapEntries) |
protected void |
addMapEntrySet(Object key,
Object value,
MapEntries mapEntries) |
boolean |
canAcquireLock(Data key,
String caller,
long threadId) |
void |
checkIfLoaded() |
int |
clear()
Called by
IMap.clear() . |
void |
clearOtherDataThanStorage(boolean onShutdown,
boolean onStorageDestroy)
Only cleans the data other than storage-data that is held on this record
store.
|
void |
clearPartition(boolean onShutdown,
boolean onStorageDestroy)
Called by
DistributedObject.destroy() or MapMigrationAwareService
Clears internal partition data. |
boolean |
containsKey(Data key,
Address callerAddress) |
boolean |
containsValue(Object value) |
protected LockStore |
createLockStore() |
Record |
createRecord(Data key,
Object value,
long ttlMillis,
long maxIdle,
long now) |
protected com.hazelcast.map.impl.recordstore.RecordStoreLoader |
createRecordStoreLoader(MapStoreContext mapStoreContext) |
Storage |
createStorage(RecordFactory recordFactory,
InMemoryFormat memoryFormat) |
boolean |
delete(Data key,
CallerProvenance provenance) |
void |
destroy()
Called by
DistributedObject.destroy() . |
void |
destroyStorageAfterClear(boolean isDuringShutdown,
boolean internal)
Calls also
clearStorage(boolean) to release allocated HD memory
of key+value pairs because destroyStorageImmediate(boolean, boolean)
only releases internal resources of backing data structure. |
void |
disposeDeferredBlocks()
This can be used to release unused resources.
|
Object |
evict(Data key,
boolean backup) |
int |
evictAll(boolean backup)
Evicts all keys except locked ones.
|
protected int |
evictRecords(Collection<Record> recordsToEvict) |
boolean |
existInMemory(Data key)
Checks if the key exist in memory without trying to load data from map-loader
|
boolean |
extendLock(Data key,
String caller,
long threadId,
long ttl) |
MapEntriesWithCursor |
fetchEntries(int tableIndex,
int size)
Fetches specified number of entries from provided tableIndex.
|
MapKeysWithCursor |
fetchKeys(int tableIndex,
int size)
Fetches specified number of keys from provided tableIndex.
|
boolean |
forceUnlock(Data dataKey) |
Object |
get(Data key,
boolean backup,
Address callerAddress,
boolean touch)
Gets record from
RecordStore . |
MapEntries |
getAll(Set<Data> keys,
Address callerAddress) |
protected List<Data> |
getKeysFromRecords(Collection<Record> clearableRecords) |
Collection<Future> |
getLoadingFutures() |
LocalRecordStoreStats |
getLocalRecordStoreStats() |
int |
getLockedEntryCount() |
String |
getLockOwnerInfo(Data key) |
MapContainer |
getMapContainer() |
MapDataStore<Data,Object> |
getMapDataStore() |
String |
getName() |
protected Collection<Record> |
getNotLockedRecords() |
protected long |
getNow() |
long |
getOwnedEntryCost() |
int |
getPartitionId()
Returns the partition id this RecordStore belongs to.
|
Record |
getRecord(Data key) |
Record |
getRecordOrNull(Data key)
Returns live record or null if record is already expired.
|
protected Record |
getRecordOrNull(Data key,
long now,
boolean backup) |
Storage<Data,? extends Record> |
getStorage() |
boolean |
hasQueryCache() |
void |
init()
Initialize the recordStore after creation
|
boolean |
isEmpty() |
protected boolean |
isKeyAndValueLoadable(Data key,
Object value) |
boolean |
isKeyLoadFinished() |
boolean |
isLoaded()
Returns
true if all key and value loading tasks have completed
on this record store. |
boolean |
isLocked(Data dataKey) |
boolean |
isLockedBy(Data key,
String caller,
long threadId) |
boolean |
isTransactionallyLocked(Data key) |
Iterator<Record> |
iterator()
Iterates over record store entries.
|
Iterator<Record> |
iterator(long now,
boolean backup)
Iterates over record store entries by respecting expiration.
|
void |
loadAll(boolean replaceExistingValues)
Triggers key and value loading if there is no ongoing or completed
key loading task, otherwise does nothing.
|
void |
loadAllFromStore(List<Data> keys,
boolean replaceExistingValues)
Triggers loading values for the given
keys from the
defined MapLoader . |
Iterator<Record> |
loadAwareIterator(long now,
boolean backup)
Iterates over record store entries but first waits map store to load.
|
protected Map<Data,Object> |
loadEntries(Set<Data> keys,
Address callerAddress) |
Record |
loadRecordOrNull(Data key,
boolean backup,
Address callerAddress) |
boolean |
localLock(Data key,
String caller,
long threadId,
long referenceId,
long ttl) |
boolean |
lock(Data key,
String caller,
long threadId,
long referenceId,
long ttl) |
void |
maybeDoInitialLoad()
Resets the map loader state if necessary and triggers initial key and
value loading if it has not been done before.
|
boolean |
merge(Data key,
EntryView mergingEntry,
MapMergePolicy mergePolicy) |
boolean |
merge(Data key,
EntryView mergingEntry,
MapMergePolicy mergePolicy,
CallerProvenance provenance)
Merges the given
EntryView via the given MapMergePolicy . |
boolean |
merge(SplitBrainMergeTypes.MapMergeTypes mergingEntry,
SplitBrainMergePolicy<Data,SplitBrainMergeTypes.MapMergeTypes> mergePolicy) |
boolean |
merge(SplitBrainMergeTypes.MapMergeTypes mergingEntry,
SplitBrainMergePolicy<Data,SplitBrainMergeTypes.MapMergeTypes> mergePolicy,
CallerProvenance provenance)
Merges the given
SplitBrainMergeTypes.MapMergeTypes via the given SplitBrainMergePolicy . |
protected void |
onStore(Record record) |
protected boolean |
persistenceEnabledFor(CallerProvenance provenance) |
Object |
put(Data key,
Object value,
long ttl,
long maxIdle) |
Record |
putBackup(Data key,
Object value,
CallerProvenance provenance) |
Record |
putBackup(Data key,
Object value,
long ttl,
long maxIdle,
boolean putTransient,
CallerProvenance provenance) |
Object |
putFromLoad(Data key,
Object value,
Address callerAddress)
Puts key-value pair to map which is the result of a load from map store operation.
|
Object |
putFromLoadBackup(Data key,
Object value)
Puts key-value pair to map which is the result of a load from map store operation on backup.
|
Object |
putIfAbsent(Data key,
Object value,
long ttl,
long maxIdle,
Address callerAddress) |
protected Object |
putInternal(Data key,
Object value,
long ttl,
long maxIdle,
boolean loadFromStore,
boolean countAsAccess) |
void |
putRecord(Data key,
Record record)
Puts a data key and a record value to record-store.
|
Object |
putTransient(Data key,
Object value,
long ttl,
long maxIdle) |
Data |
readBackupData(Data key)
This method is called directly by user threads, in other words
it is called outside of the partition threads.
|
Object |
remove(Data key,
CallerProvenance provenance) |
boolean |
remove(Data key,
Object testValue) |
void |
removeBackup(Data key,
CallerProvenance provenance)
Similar to
RecordStore##remove(Data, CallerProvenance)
except removeBackup doesn't touch mapstore since it does not return previous value. |
protected void |
removeIndex(Collection<Record> records) |
protected void |
removeIndex(Record record) |
protected Object |
removeRecord(Data key,
Record record,
long now,
CallerProvenance provenance) |
protected int |
removeRecords(Collection<Record> recordsToRemove) |
Object |
replace(Data key,
Object update) |
boolean |
replace(Data key,
Object expect,
Object update)
Sets the value to the given updated value
if
ValueComparator.isEqual(java.lang.Object, java.lang.Object, com.hazelcast.spi.serialization.SerializationService) comparison
of current value and expected value is true . |
void |
reset()
Resets the record store to it's initial state.
|
protected void |
saveIndex(Record record,
Object oldValue) |
Object |
set(Data dataKey,
Object value,
long ttl,
long maxIdle) |
void |
setPreMigrationLoadedStatus(boolean loaded)
Informs this recordStore about the loading status of the recordStore
that this store is migrated from.
|
void |
setSizeEstimator(EntryCostEstimator entryCostEstimator) |
boolean |
setTtl(Data key,
long ttl) |
boolean |
setWithUncountedAccess(Data dataKey,
Object value,
long ttl,
long maxIdle)
Does exactly the same thing as
RecordStore.set(Data, Object, long, long) except the invocation is not counted as
a read access while updating the access statics. |
int |
size()
Size may not give precise size at a specific moment
due to the expiration logic.
|
long |
softFlush() |
void |
startLoading()
Starts the map loader if there is a configured and enabled
MapLoader and the key loading has not already
been started. |
protected Data |
toData(Object value) |
boolean |
txnLock(Data key,
String caller,
long threadId,
long referenceId,
long ttl,
boolean blockReads) |
boolean |
unlock(Data key,
String caller,
long threadId,
long referenceId) |
void |
updateLoadStatus(boolean lastBatch,
Throwable exception)
Advances the state of the map key loader for this partition and sets the key
loading future result if the
lastBatch is true . |
protected void |
updateRecord(Data key,
Record record,
Object value,
long now,
boolean countAsAccess) |
protected void |
updateStatsOnGet(long now) |
protected void |
updateStatsOnPut(boolean countAsAccess,
long now) |
protected void |
updateStatsOnPut(long hits) |
accessRecord, doPostEvictionOperations, evictEntries, evictExpiredEntries, get, getExpiredKeysQueue, getOrNullIfExpired, isExpirable, isExpired, isMaxIdleDefined, isTtlDefined, markRecordStoreExpirable, mergeRecordExpiration, mergeRecordExpiration, sampleAndForceRemoveEntries, shouldEvict
protected final ILogger logger
protected final com.hazelcast.map.impl.recordstore.RecordStoreLoader recordStoreLoader
protected final MapKeyLoader keyLoader
protected final Collection<Future> loadingFutures
loadAll(boolean)
,
loadAllFromStore(List, boolean)
protected final int partitionId
protected final String name
protected final LockStore lockStore
protected final MapContainer mapContainer
protected final RecordFactory recordFactory
protected final InMemoryFormat inMemoryFormat
protected final MapStoreContext mapStoreContext
protected final ValueComparator valueComparator
protected final MapServiceContext mapServiceContext
protected final SerializationService serializationService
protected final MapDataStore<Data,Object> mapDataStore
protected final LocalRecordStoreStatsImpl stats
protected final RecordStoreMutationObserver<Record> mutationObserver
public DefaultRecordStore(MapContainer mapContainer, int partitionId, MapKeyLoader keyLoader, ILogger logger)
public MapDataStore<Data,Object> getMapDataStore()
public long softFlush()
MapDataStore.softFlush()
public void putRecord(Data key, Record record)
RecordStore
key
- the data key to put record store.record
- the value for record store.MapReplicationOperation
public Record putBackup(Data key, Object value, CallerProvenance provenance)
key
- the keyvalue
- the value to put backupprovenance
- origin of call to this method.public Record putBackup(Data key, Object value, long ttl, long maxIdle, boolean putTransient, CallerProvenance provenance)
key
- the key to be processed.value
- the value to be processed.ttl
- milliseconds. Check out MapProxySupport.putInternal(java.lang.Object, com.hazelcast.nio.serialization.Data, long, java.util.concurrent.TimeUnit, long, java.util.concurrent.TimeUnit)
maxIdle
- milliseconds. Check out MapProxySupport.putInternal(java.lang.Object, com.hazelcast.nio.serialization.Data, long, java.util.concurrent.TimeUnit, long, java.util.concurrent.TimeUnit)
putTransient
- true
if putting transient entry, otherwise false
provenance
- origin of call to this method.public Iterator<Record> iterator()
RecordStore
public Iterator<Record> iterator(long now, boolean backup)
RecordStore
public MapKeysWithCursor fetchKeys(int tableIndex, int size)
RecordStore
MapKeysWithCursor
which is a holder for keys and next index to read from.public MapEntriesWithCursor fetchEntries(int tableIndex, int size)
RecordStore
MapEntriesWithCursor
which is a holder for entries and next index to read from.public Iterator<Record> loadAwareIterator(long now, boolean backup)
RecordStore
IMap.keySet(com.hazelcast.query.Predicate)
,
this method can be used to return a read-only iterator.now
- current time in millisbackup
- true
if a backup partition, otherwise false
.public int size()
public boolean isEmpty()
public boolean containsValue(Object value)
public boolean txnLock(Data key, String caller, long threadId, long referenceId, long ttl, boolean blockReads)
public boolean localLock(Data key, String caller, long threadId, long referenceId, long ttl)
public boolean forceUnlock(Data dataKey)
public boolean isLocked(Data dataKey)
public boolean isTransactionallyLocked(Data key)
protected List<Data> getKeysFromRecords(Collection<Record> clearableRecords)
protected int removeRecords(Collection<Record> recordsToRemove)
protected int evictRecords(Collection<Record> recordsToEvict)
protected Collection<Record> getNotLockedRecords()
public int evictAll(boolean backup)
RecordStore
backup
- true
if a backup partition, otherwise false
.public void removeBackup(Data key, CallerProvenance provenance)
RecordStore
RecordStore##remove(Data, CallerProvenance)
except removeBackup doesn't touch mapstore since it does not return previous value.public boolean delete(Data key, CallerProvenance provenance)
key
- the key to be removedprovenance
- origin of call to this method.true
if entry is deleted, otherwise returns false
public Object remove(Data key, CallerProvenance provenance)
key
- the key to be removedprovenance
- origin of call to this method.public Object get(Data key, boolean backup, Address callerAddress, boolean touch)
RecordStore
RecordStore
.
Loads missing keys from map store.key
- key.backup
- true
if a backup partition, otherwise false
.touch
- when true
, if an existing record was found for the given key,
then its last access time is updated.RecordStore
public Data readBackupData(Data key)
key
- key to be accessedData
independent of InMemoryFormat
public MapEntries getAll(Set<Data> keys, Address callerAddress)
protected void addMapEntrySet(Object key, Object value, MapEntries mapEntries)
protected void addMapEntrySet(Map<Object,Object> entries, MapEntries mapEntries)
public boolean existInMemory(Data key)
RecordStore
public boolean hasQueryCache()
true
if this IMap has any query-cache, otherwise return false
public boolean setTtl(Data key, long ttl)
public Object set(Data dataKey, Object value, long ttl, long maxIdle)
MapLoader
public Object put(Data key, Object value, long ttl, long maxIdle)
MapLoader
protected Object putInternal(Data key, Object value, long ttl, long maxIdle, boolean loadFromStore, boolean countAsAccess)
public boolean merge(SplitBrainMergeTypes.MapMergeTypes mergingEntry, SplitBrainMergePolicy<Data,SplitBrainMergeTypes.MapMergeTypes> mergePolicy)
public boolean merge(SplitBrainMergeTypes.MapMergeTypes mergingEntry, SplitBrainMergePolicy<Data,SplitBrainMergeTypes.MapMergeTypes> mergePolicy, CallerProvenance provenance)
RecordStore
SplitBrainMergeTypes.MapMergeTypes
via the given SplitBrainMergePolicy
.mergingEntry
- the SplitBrainMergeTypes.MapMergeTypes
instance to mergemergePolicy
- the SplitBrainMergePolicy
instance to applyprovenance
- origin of call to this method.true
if merge is applied, otherwise false
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy)
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy, CallerProvenance provenance)
RecordStore
EntryView
via the given MapMergePolicy
.key
- the key to be mergedmergingEntry
- the EntryView
instance to mergemergePolicy
- the MapMergePolicy
instance to applyprovenance
- origin of call to this method.true
if merge is applied, otherwise false
public boolean replace(Data key, Object expect, Object update)
RecordStore
ValueComparator.isEqual(java.lang.Object, java.lang.Object, com.hazelcast.spi.serialization.SerializationService)
comparison
of current value and expected value is true
.key
- key which's value is requested to be replaced.expect
- the expected valueupdate
- the new valuetrue
if successful. False return indicates that
the actual value was not equal to the expected value.public Object putFromLoad(Data key, Object value, Address callerAddress)
RecordStore
key
- key to put.value
- to put.PutFromLoadAllOperation
public Object putFromLoadBackup(Data key, Object value)
RecordStore
key
- key to put.value
- to put.PutFromLoadAllBackupOperation
public boolean setWithUncountedAccess(Data dataKey, Object value, long ttl, long maxIdle)
RecordStore
RecordStore.set(Data, Object, long, long)
except the invocation is not counted as
a read access while updating the access statics.public Object putIfAbsent(Data key, Object value, long ttl, long maxIdle, Address callerAddress)
protected Object removeRecord(Data key, @Nonnull Record record, long now, CallerProvenance provenance)
public Record getRecordOrNull(Data key)
RecordStore
key
- key to be accessedRecordStore.get(com.hazelcast.nio.serialization.Data, boolean, com.hazelcast.nio.Address, boolean)
protected void onStore(Record record)
public boolean isKeyLoadFinished()
true
if the key loading and dispatching has finished on
this record storepublic void checkIfLoaded()
public boolean isLoaded()
RecordStore
true
if all key and value loading tasks have completed
on this record store.public Collection<Future> getLoadingFutures()
public void startLoading()
RecordStore
MapLoader
and the key loading has not already
been started.
The loading may start again if there was a migration and the record store
on the migration source has started but not completed the loading.public void setPreMigrationLoadedStatus(boolean loaded)
RecordStore
RecordStore.startLoading()
,
otherwise has no effect.
This method should be deleted when the map's lifecycle has been cleaned-up. Currently it's impossible to pass additional state when the record store is created, thus this state has to be passed in post-creation setters which is cumbersome and error-prone.
public void loadAll(boolean replaceExistingValues)
RecordStore
replaceExistingValues
- if the existing entries for the loaded keys should be replacedpublic void loadAllFromStore(List<Data> keys, boolean replaceExistingValues)
RecordStore
keys
from the
defined MapLoader
.
The values will be loaded asynchronously and this method will
return as soon as the value loading task has been offloaded
to a different thread.keys
- the keys for which values will be loadedreplaceExistingValues
- if the existing entries for the keys should
be replaced with the loaded valuespublic void updateLoadStatus(boolean lastBatch, Throwable exception)
RecordStore
lastBatch
is true
.
If there was an exception during key loading, you may pass it as the
exception
paramter and it will be set as the result of the future.
lastBatch
- if the last key batch was sentexception
- an exception that occurred during key loadingpublic void maybeDoInitialLoad()
RecordStore
public int clear()
RecordStore
IMap.clear()
.
Clears data in this record store.public void reset()
RecordStore
RecordStore.putRecord(Data, Record)
public void destroy()
RecordStore
DistributedObject.destroy()
.
Destroys data in this record store.public void clearPartition(boolean onShutdown, boolean onStorageDestroy)
RecordStore
DistributedObject.destroy()
or MapMigrationAwareService
Clears internal partition data.onShutdown
- true if close
is called during
MapService shutdown, false otherwise.onStorageDestroy
- true if record-store will be destroyed,
otherwise false.public void clearOtherDataThanStorage(boolean onShutdown, boolean onStorageDestroy)
public void destroyStorageAfterClear(boolean isDuringShutdown, boolean internal)
clearStorage(boolean)
to release allocated HD memory
of key+value pairs because destroyStorageImmediate(boolean, boolean)
only releases internal resources of backing data structure.isDuringShutdown
- Storage.clear(boolean)
internal
- see RecordStoreMutationObserver.onDestroy(boolean)
}protected boolean persistenceEnabledFor(@Nonnull CallerProvenance provenance)
public LocalRecordStoreStats getLocalRecordStoreStats()
getLocalRecordStoreStats
in interface RecordStore<Record>
public void init()
RecordStore
init
in interface RecordStore<Record>
public Record createRecord(Data key, Object value, long ttlMillis, long maxIdle, long now)
createRecord
in interface RecordStore<Record>
public Storage createStorage(RecordFactory recordFactory, InMemoryFormat memoryFormat)
createStorage
in interface RecordStore<Record>
public String getName()
getName
in interface RecordStore<Record>
public MapContainer getMapContainer()
getMapContainer
in interface RecordStore<Record>
public long getOwnedEntryCost()
getOwnedEntryCost
in interface RecordStore<Record>
protected long getNow()
protected void updateRecord(Data key, Record record, Object value, long now, boolean countAsAccess)
public int getPartitionId()
RecordStore
getPartitionId
in interface RecordStore<Record>
protected void removeIndex(Record record)
protected void removeIndex(Collection<Record> records)
protected LockStore createLockStore()
public int getLockedEntryCount()
getLockedEntryCount
in interface RecordStore<Record>
protected com.hazelcast.map.impl.recordstore.RecordStoreLoader createRecordStoreLoader(MapStoreContext mapStoreContext)
public void setSizeEstimator(EntryCostEstimator entryCostEstimator)
public void disposeDeferredBlocks()
RecordStore
disposeDeferredBlocks
in interface RecordStore<Record>
public Storage<Data,? extends Record> getStorage()
getStorage
in interface RecordStore<Record>
protected void updateStatsOnPut(boolean countAsAccess, long now)
protected void updateStatsOnPut(long hits)
protected void updateStatsOnGet(long now)
Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.