public class DefaultRecordStore extends Object
Modifier and Type | Field and Description |
---|---|
protected InMemoryFormat |
inMemoryFormat |
protected MapKeyLoader |
keyLoader |
protected Collection<Future> |
loadingFutures |
protected LockStore |
lockStore |
protected ILogger |
logger |
protected MapContainer |
mapContainer |
protected MapDataStore<Data,Object> |
mapDataStore |
protected MapServiceContext |
mapServiceContext |
protected MapStoreContext |
mapStoreContext |
protected String |
name |
protected int |
partitionId |
protected RecordFactory |
recordFactory |
protected com.hazelcast.map.impl.recordstore.RecordStoreLoader |
recordStoreLoader |
protected SerializationService |
serializationService |
protected Storage<Data,Record> |
storage |
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) |
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 Object |
copyToHeap(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 |
disposeDeferredBlocks()
This can be used to release unused resources.
|
void |
doPostEvictionOperations(Data key,
Object value,
boolean isExpired)
- Sends eviction event.
|
Object |
evict(Data key,
boolean backup) |
int |
evictAll(boolean backup)
Evicts all keys except locked ones.
|
void |
evictEntries(long now) |
void |
evictExpiredEntries(int percentage,
boolean backup)
Do expiration operations.
|
boolean |
extendLock(Data key,
String caller,
long threadId,
long ttl) |
void |
flush() |
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) |
long |
getHeapCost() |
protected List<Data> |
getKeysFromRecords(Collection<Record> clearableRecords) |
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.
|
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 |
init()
Initialize the recordStore after creation
|
boolean |
isEmpty() |
boolean |
isEvictionEnabled() |
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 |
isLoaded() |
boolean |
isLocked(Data dataKey) |
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.
|
Set<Data> |
keySet() |
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 |
loadEntries(Set<Data> keys) |
Record |
loadRecordOrNull(Data key,
boolean backup) |
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) |
void |
onKeyLoad(ExecutionCallback<Boolean> callback)
Register a callback for when key loading is complete
|
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.
|
void |
putTransient(Data key,
Object value,
long ttl) |
Data |
readBackupData(Data key)
Called when
MapConfig.isReadBackupData() is true from
MapProxySupport.getInternal(com.hazelcast.nio.serialization.Data)
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
RecordFactory.isEquals(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 |
resetAccessSequenceNumber() |
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 |
setSizeEstimator(SizeEstimator sizeEstimator) |
protected boolean |
shouldEvict(long now) |
int |
size()
Size may not give precise size at a specific moment
due to the expiration logic.
|
void |
startLoading()
Starts mapLoader
|
protected Data |
toData(Object value) |
boolean |
txnLock(Data key,
String caller,
long threadId,
long referenceId,
long ttl) |
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 final ILogger logger
protected final LockStore lockStore
protected final com.hazelcast.map.impl.recordstore.RecordStoreLoader recordStoreLoader
protected final MapKeyLoader keyLoader
protected final Collection<Future> loadingFutures
protected final RecordFactory recordFactory
protected final String name
protected final MapContainer mapContainer
protected final MapServiceContext mapServiceContext
protected final SerializationService serializationService
protected final MapDataStore<Data,Object> mapDataStore
protected final MapStoreContext mapStoreContext
protected final int partitionId
protected final InMemoryFormat inMemoryFormat
public DefaultRecordStore(MapContainer mapContainer, int partitionId, MapKeyLoader keyLoader, ILogger logger)
public void startLoading()
RecordStore
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.replaceExistingValues
- true
if need to replace existing values otherwise false
public void updateLoadStatus(boolean lastBatch, Throwable exception)
public void maybeDoInitialLoad()
RecordStore
public void destroy()
public void onKeyLoad(ExecutionCallback<Boolean> callback)
RecordStore
public void checkIfLoaded()
public void flush()
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(com.hazelcast.nio.serialization.Data, 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 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 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(com.hazelcast.nio.serialization.Data)
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 containsKey(Data key)
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy)
public boolean replace(Data key, Object expect, Object update)
RecordStore
RecordFactory.isEquals(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 Object putFromLoad(Data key, Object value, long ttl)
RecordStore
key
- key to put.value
- to put.ttl
- time to live seconds.PutAllOperation
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 boolean isEvictionEnabled()
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
.protected void resetAccessSequenceNumber()
public void evictEntries(long now)
protected boolean shouldEvict(long now)
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(Data key, Object value, boolean isExpired)
key
- the key to be processed.value
- the value to be processed.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 getHeapCost()
getHeapCost
in interface RecordStore<Record>
protected long getNow()
protected void accessRecord(Record record)
public int getPartitionId()
getPartitionId
in interface RecordStore<Record>
protected void removeIndex(Record record)
protected void removeIndex(Collection<Record> records)
protected LockStore createLockStore()
protected com.hazelcast.map.impl.recordstore.RecordStoreLoader createRecordStoreLoader(MapStoreContext mapStoreContext)
public void setSizeEstimator(SizeEstimator sizeEstimator)
public void disposeDeferredBlocks()
RecordStore
disposeDeferredBlocks
in interface RecordStore<Record>
public Storage<Data,? extends Record> getStorage()
getStorage
in interface RecordStore<Record>
Copyright © 2016 Hazelcast, Inc.. All Rights Reserved.