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() |
void |
clearPartition(boolean onShutdown)
Clears internal partition data.
|
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) |
void |
decreaseHits(long hits)
Decreases the number of hits of the locally owned entries of this partition.
|
boolean |
delete(Data key) |
void |
destroy() |
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() |
long |
getHits()
Returns the number of hits (reads) of the locally owned entries of this partition.
|
protected List<Data> |
getKeysFromRecords(Collection<Record> clearableRecords) |
long |
getLastAccessTime()
Returns the last access (read) time of the locally owned entries of this partition.
|
long |
getLastUpdateTime()
Returns the last update time of the locally owned entries of this partition.
|
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() |
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() |
void |
increaseHits()
Increases the number of hits of the locally owned entries of this partition.
|
void |
increaseHits(long hits)
Increases the number of hits of the locally owned entries of this partition.
|
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 |
isKeyAndValueLoadable(Data key,
Object value) |
boolean |
isKeyLoadFinished() |
boolean |
isLoaded() |
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)
Loads all keys and values
|
void |
loadAllFromStore(List<Data> keys,
boolean replaceExistingValues)
Loads all given keys from defined map store.
|
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()
Performs initial loading from a MapLoader if it has not been done before
|
boolean |
merge(Data key,
EntryView mergingEntry,
MapMergePolicy mergePolicy) |
protected void |
mergeRecordExpiration(Record record,
EntryView 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 |
putFromLoad(Data key,
Object value,
long ttl)
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) |
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
com.hazelcast.map.impl.record.RecordFactory#isEquals comparison
of current value and expected value is true . |
void |
reset()
Resets the record store to it's initial state.
|
protected void |
resetStats() |
protected void |
saveIndex(Record record,
Object oldValue) |
boolean |
set(Data dataKey,
Object value,
long ttl)
Returns
true if key doesn't exist previously, otherwise returns false . |
void |
setLastAccessTime(long time)
Increases the number of hits of the locally owned entries of this partition.
|
void |
setLastUpdateTime(long time)
Increases the number of hits of the locally owned entries of this partition.
|
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 |
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 mapLoader
|
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) |
protected void |
updateRecord(Data key,
Record record,
Object value,
long now) |
protected void |
updateStatsOnGet(long now) |
protected void |
updateStatsOnPut(boolean newRecord,
long now) |
protected void |
updateStatsOnPut(long hits) |
protected void |
updateStatsOnRemove(long hits) |
protected final ILogger logger
protected final com.hazelcast.map.impl.recordstore.RecordStoreLoader recordStoreLoader
protected final MapKeyLoader keyLoader
protected final Collection<Future> loadingFutures
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 String name
protected final MapContainer mapContainer
protected final int partitionId
protected final MapServiceContext mapServiceContext
protected final SerializationService serializationService
protected final InMemoryFormat inMemoryFormat
protected final RecordFactory recordFactory
protected final RecordComparator recordComparator
protected final MapStoreContext mapStoreContext
protected final MapDataStore<Data,Object> mapDataStore
protected final LockStore lockStore
protected final MapEventJournal eventJournal
public DefaultRecordStore(MapContainer mapContainer, int partitionId, MapKeyLoader keyLoader, ILogger logger)
public void startLoading()
RecordStore
public void setPreMigrationLoadedStatus(boolean loaded)
RecordStore
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 this state has to be passed in post-creation setters which is cumbersome and error-prone.
public boolean isLoaded()
public void loadAll(boolean replaceExistingValues)
RecordStore
replaceExistingValues
- true
if need to replace existing values otherwise false
public void loadAllFromStore(List<Data> keys, boolean replaceExistingValues)
RecordStore
keys
- keys to be loaded.public void updateLoadStatus(boolean lastBatch, Throwable exception)
public void maybeDoInitialLoad()
RecordStore
public void destroy()
public boolean isKeyLoadFinished()
public void checkIfLoaded()
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.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()
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 merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy)
public boolean replace(Data key, Object expect, Object update)
RecordStore
com.hazelcast.map.impl.record.RecordFactory#isEquals
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 Object putFromLoad(Data key, Object value, long ttl)
RecordStore
key
- key to put.value
- to put.ttl
- time to live seconds.PutFromLoadAllOperation
public boolean set(Data dataKey, Object value, long ttl)
RecordStore
true
if key doesn't exist previously, otherwise returns false
.IMap.set(Object, Object)
public MapDataStore<Data,Object> getMapDataStore()
public Record getRecordOrNull(Data key)
RecordStore
key
- key to be accessedRecordStore.get(com.hazelcast.nio.serialization.Data, boolean)
protected void onStore(Record record)
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 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)
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()
public int getPartitionId()
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>
public long getHits()
LocalRecordStoreStats
getHits
in interface LocalRecordStoreStats
public long getLastAccessTime()
LocalRecordStoreStats
getLastAccessTime
in interface LocalRecordStoreStats
public long getLastUpdateTime()
LocalRecordStoreStats
getLastUpdateTime
in interface LocalRecordStoreStats
public void increaseHits()
LocalRecordStoreStats
increaseHits
in interface LocalRecordStoreStats
public void increaseHits(long hits)
LocalRecordStoreStats
increaseHits
in interface LocalRecordStoreStats
public void decreaseHits(long hits)
LocalRecordStoreStats
decreaseHits
in interface LocalRecordStoreStats
public void setLastAccessTime(long time)
LocalRecordStoreStats
setLastAccessTime
in interface LocalRecordStoreStats
public void setLastUpdateTime(long time)
LocalRecordStoreStats
setLastUpdateTime
in interface LocalRecordStoreStats
protected void updateStatsOnPut(boolean newRecord, long now)
protected void updateStatsOnPut(long hits)
protected void updateStatsOnGet(long now)
protected void updateStatsOnRemove(long hits)
protected void resetStats()
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.