public class DefaultRecordStore extends Object
DEFAULT_TTL
Constructor and Description |
---|
DefaultRecordStore(MapContainer mapContainer,
int partitionId,
MapKeyLoader keyLoader,
ILogger logger) |
Modifier and Type | Method and Description |
---|---|
protected void |
accessRecord(Record record,
long now) |
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() |
protected void |
clearIndexes() |
protected void |
clearLockStore() |
protected void |
clearMapStore() |
void |
clearPartition(boolean onShutdown)
Clears internal partition data.
|
protected void |
clearStorage(boolean onShutdown) |
boolean |
containsKey(Data key) |
boolean |
containsValue(Object value) |
protected LockStore |
createLockStore() |
Record |
createRecord(Object value,
long ttlMillis,
long now) |
protected com.hazelcast.map.impl.recordstore.RecordStoreLoader |
createRecordStoreLoader(MapStoreContext mapStoreContext) |
Storage |
createStorage(RecordFactory recordFactory,
InMemoryFormat memoryFormat) |
boolean |
delete(Data key) |
void |
destroy() |
void |
destroyInternals()
Like
RecordStore.destroy() but does not touch state on other services
like lock service or event journal service. |
void |
disposeDeferredBlocks()
This can be used to release unused resources.
|
void |
doPostEvictionOperations(Record record,
boolean backup)
Does post eviction operations like sending events
|
Object |
evict(Data key,
boolean backup) |
int |
evictAll(boolean backup)
Evicts all keys except locked ones.
|
void |
evictEntries(Data excludedKey)
Evicts entries from this record-store.
|
void |
evictExpiredEntries(int percentage,
boolean backup)
Do expiration operations.
|
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.
|
protected void |
flush(Collection<Record> recordsToBeFlushed,
boolean backup)
Flushes evicted records to map store.
|
boolean |
forceUnlock(Data dataKey) |
Object |
get(Data key,
boolean backup)
Gets record from
RecordStore . |
MapEntries |
getAll(Set<Data> keys) |
InvalidationQueue<ExpiredKey> |
getExpiredKeys() |
protected List<Data> |
getKeysFromRecords(Collection<Record> clearableRecords) |
LocalRecordStoreStats |
getLocalRecordStoreStats() |
int |
getLockedEntryCount() |
String |
getLockOwnerInfo(Data key) |
MapContainer |
getMapContainer() |
MapDataStore<Data,Object> |
getMapDataStore() |
String |
getName() |
protected Collection<Record> |
getNotLockedRecords() |
protected long |
getNow() |
protected Record |
getOrNullIfExpired(Record record,
long now,
boolean backup)
Check if record is reachable according to TTL or idle times.
|
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() |
boolean |
isExpirable() |
boolean |
isExpired(Record record,
long now,
boolean backup)
Checks whether a record is expired or not.
|
protected boolean |
isInfiniteTTL(long ttl) |
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) |
Record |
loadRecordOrNull(Data key,
boolean backup) |
boolean |
localLock(Data key,
String caller,
long threadId,
long referenceId,
long ttl) |
boolean |
lock(Data key,
String caller,
long threadId,
long referenceId,
long ttl) |
protected void |
markRecordStoreExpirable(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)
Merges the given
EntryView via the given MapMergePolicy . |
boolean |
merge(SplitBrainMergeTypes.MapMergeTypes mergingEntry,
SplitBrainMergePolicy<Data,SplitBrainMergeTypes.MapMergeTypes> mergePolicy)
Merges the given
SplitBrainMergeTypes.MapMergeTypes via the given SplitBrainMergePolicy . |
protected void |
mergeRecordExpiration(Record record,
EntryView mergingEntry) |
protected void |
mergeRecordExpiration(Record record,
SplitBrainMergeTypes.MapMergeTypes mergingEntry) |
protected void |
onStore(Record record) |
Object |
put(Data key,
Object value,
long ttl) |
Record |
putBackup(Data key,
Object value) |
Record |
putBackup(Data key,
Object value,
long ttl,
boolean putTransient) |
Object |
putFromLoad(Data key,
Object value)
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) |
protected Object |
putInternal(Data key,
Object value,
long ttl,
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) |
Data |
readBackupData(Data key)
Called when
MapConfig.isReadBackupData() is true from
MapProxySupport.getInternal(java.lang.Object)
Returns corresponding value for key as Data . |
Object |
remove(Data key) |
boolean |
remove(Data key,
Object testValue) |
void |
removeBackup(Data key)
Similar to
RecordStore.remove(com.hazelcast.nio.serialization.Data)
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) |
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
RecordComparator.isEqual(java.lang.Object, java.lang.Object) 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) |
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 |
setWithUncountedAccess(Data dataKey,
Object value,
long ttl)
Does exactly the same thing as
RecordStore.set(Data, Object, long) except the invocation is not counted as
a read access while updating the access statics. |
boolean |
shouldEvict()
Returns
true if eviction is allowed on this record-store, otherwise false |
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) |
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 long expiryDelayMillis
protected final EventService eventService
protected final MapEventPublisher mapEventPublisher
protected final Address thisAddress
protected final ExpirationManager expirationManager
protected final InvalidationQueue<ExpiredKey> expiredKeys
protected Iterator<Record> expirationIterator
protected volatile boolean hasEntryWithCustomTTL
protected final int partitionId
protected final String name
protected final LockStore lockStore
protected final MapContainer mapContainer
protected final RecordFactory recordFactory
protected final MapEventJournal eventJournal
protected final InMemoryFormat inMemoryFormat
protected final MapStoreContext mapStoreContext
protected final RecordComparator recordComparator
protected final MapServiceContext mapServiceContext
protected final SerializationService serializationService
protected final MapDataStore<Data,Object> mapDataStore
protected final LocalRecordStoreStatsImpl stats
public DefaultRecordStore(MapContainer mapContainer, int partitionId, MapKeyLoader keyLoader, ILogger logger)
public MapDataStore<Data,Object> getMapDataStore()
public void destroy()
public void destroyInternals()
RecordStore
RecordStore.destroy()
but does not touch state on other services
like lock service or event journal service.public long softFlush()
MapDataStore.softFlush()
protected void flush(Collection<Record> recordsToBeFlushed, boolean backup)
recordsToBeFlushed
- records to be flushed to map-store.backup
- true
if backup, false otherwise.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, long ttl, boolean putTransient)
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)
putTransient
- true
if putting transient entry, otherwise false
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 void clearPartition(boolean onShutdown)
RecordStore
onShutdown
- true if close
is called during MapService shutdown,
false otherwise.protected void clearLockStore()
protected void clearStorage(boolean onShutdown)
protected void clearMapStore()
protected void clearIndexes()
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)
public int clear()
protected List<Data> getKeysFromRecords(Collection<Record> clearableRecords)
protected int removeRecords(Collection<Record> recordsToRemove)
protected Collection<Record> getNotLockedRecords()
public void reset()
RecordStore.putRecord(Data, Record)
public int evictAll(boolean backup)
RecordStore
backup
- true
if a backup partition, otherwise false
.public void removeBackup(Data key)
RecordStore
RecordStore.remove(com.hazelcast.nio.serialization.Data)
except removeBackup doesn't touch mapstore since it does not return previous value.public boolean delete(Data key)
public Object get(Data key, boolean backup)
RecordStore
RecordStore
.
Loads missing keys from map store.key
- key.backup
- true
if a backup partition, otherwise false
.RecordStore
public Data readBackupData(Data key)
RecordStore
MapConfig.isReadBackupData()
is true
from
MapProxySupport.getInternal(java.lang.Object)
Returns corresponding value for key as Data
.
This adds an extra serialization step. For the reason of this behaviour please see issue 1292 on github.key
- key to be accessedData
independent of InMemoryFormat
public MapEntries getAll(Set<Data> keys)
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 containsKey(Data key)
public boolean hasQueryCache()
true
if this IMap has any query-cache, otherwise return false
public Object set(Data dataKey, Object value, long ttl)
MapLoader
public Object put(Data key, Object value, long ttl)
MapLoader
protected Object putInternal(Data key, Object value, long ttl, boolean loadFromStore, boolean countAsAccess)
public boolean merge(SplitBrainMergeTypes.MapMergeTypes mergingEntry, SplitBrainMergePolicy<Data,SplitBrainMergeTypes.MapMergeTypes> mergePolicy)
RecordStore
SplitBrainMergeTypes.MapMergeTypes
via the given SplitBrainMergePolicy
.mergingEntry
- the SplitBrainMergeTypes.MapMergeTypes
instance to mergemergePolicy
- the SplitBrainMergePolicy
instance to applytrue
if merge is applied, otherwise false
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy)
RecordStore
EntryView
via the given MapMergePolicy
.mergingEntry
- the EntryView
instance to mergemergePolicy
- the MapMergePolicy
instance to applytrue
if merge is applied, otherwise false
public boolean replace(Data key, Object expect, Object update)
RecordStore
RecordComparator.isEqual(java.lang.Object, java.lang.Object)
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)
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)
RecordStore
RecordStore.set(Data, Object, long)
except the invocation is not counted as
a read access while updating the access statics.public Record getRecordOrNull(Data key)
RecordStore
key
- key to be accessedRecordStore.get(com.hazelcast.nio.serialization.Data, 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 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 boolean isLoaded()
RecordStore
true
if all key and value loading tasks have completed
on this record store.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 void evictExpiredEntries(int percentage, boolean backup)
RecordStore
percentage
- of max expirables according to the record store size.backup
- true
if a backup partition, otherwise false
.public boolean isExpirable()
true
if record store has at least one candidate entry
for expiration else return false
.public void evictEntries(Data excludedKey)
RecordStore
excludedKey
- this key has lowest priority to be selected for evictionpublic boolean shouldEvict()
RecordStore
true
if eviction is allowed on this record-store, otherwise false
true
if eviction is allowed on this record-store, otherwise false
protected void markRecordStoreExpirable(long ttl)
protected boolean isInfiniteTTL(long ttl)
true
if the supplied ttl doesn't not represent infinity and as a result entry should be
removed after some time, otherwise return false
to indicate entry should live forever.protected Record getOrNullIfExpired(Record record, long now, boolean backup)
record
- Record
public boolean isExpired(Record record, long now, boolean backup)
RecordStore
record
- the record from record-store.now
- current time in millisbackup
- true
if a backup partition, otherwise false
.true
if the record is expired, false
otherwise.public void doPostEvictionOperations(Record record, boolean backup)
RecordStore
record
- record to processbackup
- true
if a backup partition, otherwise false
.public InvalidationQueue<ExpiredKey> getExpiredKeys()
protected void accessRecord(Record record, long now)
protected void mergeRecordExpiration(Record record, SplitBrainMergeTypes.MapMergeTypes mergingEntry)
public LocalRecordStoreStats getLocalRecordStoreStats()
getLocalRecordStoreStats
in interface RecordStore<Record>
public void init()
RecordStore
init
in interface RecordStore<Record>
public Record createRecord(Object value, long ttlMillis, 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 © 2018 Hazelcast, Inc.. All Rights Reserved.