com.hazelcast.map.impl
Class DefaultRecordStore

java.lang.Object
  extended by com.hazelcast.map.impl.DefaultRecordStore
All Implemented Interfaces:
RecordStore

public class DefaultRecordStore
extends Object
implements RecordStore

Default implementation of record-store.


Field Summary
protected static long DEFAULT_TTL
           
protected  MapContainer mapContainer
           
protected  MapServiceContext mapServiceContext
           
protected  String name
           
protected  int partitionId
           
protected  RecordFactory recordFactory
           
protected  ConcurrentMap<Data,Record> records
           
protected  SerializationService serializationService
           
 
Constructor Summary
DefaultRecordStore(MapContainer mapContainer, int partitionId)
           
 
Method Summary
protected  void accessRecord(Record record)
           
protected  void accessRecord(Record record, long now)
           
protected  long calculateRecordHeapCost(Collection<Record> collection)
          Returns total heap cost of collection.
protected  long calculateRecordHeapCost(Record record)
           
 boolean canAcquireLock(Data key, String caller, long threadId)
           
 void checkIfLoaded()
           
 int clear()
           
 void clearPartition()
           
protected  void clearRecordsMap(Map<Data,Record> excludeRecords)
           
 boolean containsKey(Data key)
           
 boolean containsValue(Object value)
           
protected  LockStore createLockStore()
           
protected  Record createRecord(Data key, Object value, long now)
           
protected  Record createRecord(Data key, Object value, long ttl, long now)
           
protected  com.hazelcast.map.impl.RecordStoreLoader createRecordStoreLoader()
           
 boolean delete(Data key)
           
 Set<Map.Entry<Data,Data>> entrySetData()
           
 Object evict(Data key, boolean backup)
           
 int evictAll(boolean backup)
          Evicts all keys except locked ones.
 void evictEntries(long now, boolean backup)
          TODO make checkEvictable fast by carrying threshold logic to partition.
 void evictExpiredEntries(int percentage, boolean backup)
          Do expiration operations.
 boolean extendLock(Data key, String caller, long threadId, long ttl)
           
 void flush()
           
 boolean forceUnlock(Data dataKey)
           
 Object get(Data key, boolean backup)
          Gets record from RecordStore.
 MapEntrySet getAll(Set<Data> keys)
           
 long getHeapCost()
           
 String getLockOwnerInfo(Data key)
           
 MapContainer getMapContainer()
           
 MapDataStore<Data,Object> getMapDataStore()
           
 Map.Entry<Data,Object> getMapEntry(Data key, long now)
           
 String getName()
           
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)
           
 Map<Data,Record> getRecordMap()
          Returns records map.
 Record getRecordOrNull(Data key)
          Returns live record or null if record is already expired.
 boolean isEmpty()
           
 boolean isExpirable()
           
 boolean isExpired(Record record, long now, boolean backup)
           
 boolean isLoaded()
           
 boolean isLocked(Data dataKey)
           
 boolean isTransactionallyLocked(Data key)
           
 Iterator<Record> iterator()
          Iterates over record store values.
 Iterator<Record> iterator(long now, boolean backup)
          Iterates over record store values by respecting expiration.
 Set<Data> keySet()
           
 void loadAllFromStore(List<Data> keys, boolean replaceExistingValues)
          Loads all keys from defined map store.
 Iterator<Record> loadAwareIterator(long now, boolean backup)
          Iterates over record store values but first waits map store to load.
protected  void markRecordStoreExpirable(long ttl)
           
 boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy)
           
protected  void onStore(Record record)
           
protected  void postReadCleanUp(long now, boolean backup)
          If there is no clean-up caused by puts after some time, try to clean-up from gets.
 Object put(Data key, Object value, long ttl)
           
 void put(Map.Entry<Data,Object> entry)
           
 Record putBackup(Data key, Object value)
           
 Record putBackup(Data key, Object value, long ttl)
           
 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 putIfAbsent(Data key, Object value, long ttl)
           
 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(Data key)
           
protected  void removeIndex(Set<Data> keys)
           
protected  void removeIndexByPreservingKeys(Set<Data> keysToRemove, Set<Data> keysToPreserve)
          Removes indexes by excluding keysToPreserve.
 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()
           
protected  void resetAccessSequenceNumber()
           
protected  void resetSizeEstimator()
           
protected  void saveIndex(Record record)
           
 boolean set(Data key, Object value, long ttl)
           
 void setLoaded(boolean loaded)
           
 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.
protected  Data toData(Object value)
           
 boolean tryPut(Data key, Object value, long ttl)
           
 boolean txnLock(Data key, String caller, long threadId, long ttl)
           
 boolean unlock(Data key, String caller, long threadId)
           
protected  void updateRecord(Record record, Object value, long now)
           
protected  void updateSizeEstimator(long recordSize)
           
 Collection<Data> valuesData()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.hazelcast.map.impl.RecordStore
evictEntries, evictExpiredEntries, getHeapCost, getMapContainer, getName, getPartitionId, isExpirable
 

Field Detail

DEFAULT_TTL

protected static final long DEFAULT_TTL
See Also:
Constant Field Values

records

protected final ConcurrentMap<Data,Record> records

recordFactory

protected final RecordFactory recordFactory

name

protected final String name

mapContainer

protected final MapContainer mapContainer

mapServiceContext

protected final MapServiceContext mapServiceContext

serializationService

protected final SerializationService serializationService

partitionId

protected final int partitionId
Constructor Detail

DefaultRecordStore

public DefaultRecordStore(MapContainer mapContainer,
                          int partitionId)
Method Detail

isLoaded

public boolean isLoaded()
Specified by:
isLoaded in interface RecordStore

setLoaded

public void setLoaded(boolean loaded)
Specified by:
setLoaded in interface RecordStore

checkIfLoaded

public void checkIfLoaded()
Specified by:
checkIfLoaded in interface RecordStore

flush

public void flush()
Specified by:
flush in interface RecordStore

getRecord

public Record getRecord(Data key)
Specified by:
getRecord in interface RecordStore

putRecord

public void putRecord(Data key,
                      Record record)
Description copied from interface: RecordStore
Puts a data key and a record value to record-store. Used in replication operations.

Specified by:
putRecord in interface RecordStore
Parameters:
key - the data key to put record store.
record - the value for record store.
See Also:
MapReplicationOperation

putBackup

public Record putBackup(Data key,
                        Object value)
Specified by:
putBackup in interface RecordStore

putBackup

public Record putBackup(Data key,
                        Object value,
                        long ttl)
Specified by:
putBackup in interface RecordStore
Parameters:
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)
Returns:
previous record if exists otherwise null.

iterator

public Iterator<Record> iterator()
Description copied from interface: RecordStore
Iterates over record store values.

Specified by:
iterator in interface RecordStore
Returns:
read only iterator for map values.

iterator

public Iterator<Record> iterator(long now,
                                 boolean backup)
Description copied from interface: RecordStore
Iterates over record store values by respecting expiration.

Specified by:
iterator in interface RecordStore
Returns:
read only iterator for map values.

loadAwareIterator

public Iterator<Record> loadAwareIterator(long now,
                                          boolean backup)
Description copied from interface: RecordStore
Iterates over record store values but first waits map store to load. If an operation needs to wait a data source load like query operations IMap.keySet(com.hazelcast.query.Predicate), this method can be used to return a read-only iterator.

Specified by:
loadAwareIterator in interface RecordStore
Parameters:
now - current time in millis
backup - true if a backup partition, otherwise false.
Returns:
read only iterator for map values.

getRecordMap

public Map<Data,Record> getRecordMap()
Description copied from interface: RecordStore
Returns records map.

Specified by:
getRecordMap in interface RecordStore
See Also:
RecordStoreLoader

clearPartition

public void clearPartition()
Specified by:
clearPartition in interface RecordStore

size

public int size()
Size may not give precise size at a specific moment due to the expiration logic. But eventually, it should be correct.

Specified by:
size in interface RecordStore
Returns:
record store size.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface RecordStore

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface RecordStore

txnLock

public boolean txnLock(Data key,
                       String caller,
                       long threadId,
                       long ttl)
Specified by:
txnLock in interface RecordStore

extendLock

public boolean extendLock(Data key,
                          String caller,
                          long threadId,
                          long ttl)
Specified by:
extendLock in interface RecordStore

unlock

public boolean unlock(Data key,
                      String caller,
                      long threadId)
Specified by:
unlock in interface RecordStore

forceUnlock

public boolean forceUnlock(Data dataKey)
Specified by:
forceUnlock in interface RecordStore

isLocked

public boolean isLocked(Data dataKey)
Specified by:
isLocked in interface RecordStore

isTransactionallyLocked

public boolean isTransactionallyLocked(Data key)
Specified by:
isTransactionallyLocked in interface RecordStore

canAcquireLock

public boolean canAcquireLock(Data key,
                              String caller,
                              long threadId)
Specified by:
canAcquireLock in interface RecordStore

getLockOwnerInfo

public String getLockOwnerInfo(Data key)
Specified by:
getLockOwnerInfo in interface RecordStore

entrySetData

public Set<Map.Entry<Data,Data>> entrySetData()
Specified by:
entrySetData in interface RecordStore

getMapEntry

public Map.Entry<Data,Object> getMapEntry(Data key,
                                          long now)
Specified by:
getMapEntry in interface RecordStore

keySet

public Set<Data> keySet()
Specified by:
keySet in interface RecordStore

valuesData

public Collection<Data> valuesData()
Specified by:
valuesData in interface RecordStore

clear

public int clear()
Specified by:
clear in interface RecordStore

reset

public void reset()
Specified by:
reset in interface RecordStore

evict

public Object evict(Data key,
                    boolean backup)
Specified by:
evict in interface RecordStore

evictAll

public int evictAll(boolean backup)
Description copied from interface: RecordStore
Evicts all keys except locked ones.

Specified by:
evictAll in interface RecordStore
Parameters:
backup - true if a backup partition, otherwise false.
Returns:
number of evicted entries.

removeBackup

public void removeBackup(Data key)
Description copied from interface: RecordStore
Similar to RecordStore.remove(com.hazelcast.nio.serialization.Data) except removeBackup doesn't touch mapstore since it does not return previous value.

Specified by:
removeBackup in interface RecordStore

remove

public Object remove(Data key)
Specified by:
remove in interface RecordStore

remove

public boolean remove(Data key,
                      Object testValue)
Specified by:
remove in interface RecordStore

delete

public boolean delete(Data key)
Specified by:
delete in interface RecordStore

get

public Object get(Data key,
                  boolean backup)
Description copied from interface: RecordStore
Gets record from RecordStore. Loads missing keys from map store.

Specified by:
get in interface RecordStore
Parameters:
key - key.
backup - true if a backup partition, otherwise false.
Returns:
value of an entry in RecordStore

readBackupData

public Data readBackupData(Data key)
Description copied from interface: RecordStore
Called when 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.

Specified by:
readBackupData in interface RecordStore
Parameters:
key - key to be accessed
Returns:
value as Data independent of InMemoryFormat

getAll

public MapEntrySet getAll(Set<Data> keys)
Specified by:
getAll in interface RecordStore

containsKey

public boolean containsKey(Data key)
Specified by:
containsKey in interface RecordStore

put

public void put(Map.Entry<Data,Object> entry)
Specified by:
put in interface RecordStore

put

public Object put(Data key,
                  Object value,
                  long ttl)
Specified by:
put in interface RecordStore

set

public boolean set(Data key,
                   Object value,
                   long ttl)
Specified by:
set in interface RecordStore

merge

public boolean merge(Data key,
                     EntryView mergingEntry,
                     MapMergePolicy mergePolicy)
Specified by:
merge in interface RecordStore

replace

public Object replace(Data key,
                      Object update)
Specified by:
replace in interface RecordStore

replace

public boolean replace(Data key,
                       Object expect,
                       Object update)
Description copied from interface: RecordStore
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.

Specified by:
replace in interface RecordStore
Parameters:
key - key which's value is requested to be replaced.
expect - the expected value
update - the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

putTransient

public void putTransient(Data key,
                         Object value,
                         long ttl)
Specified by:
putTransient in interface RecordStore

putFromLoad

public Object putFromLoad(Data key,
                          Object value)
Description copied from interface: RecordStore
Puts key-value pair to map which is the result of a load from map store operation.

Specified by:
putFromLoad in interface RecordStore
Parameters:
key - key to put.
value - to put.
Returns:
the previous value associated with key, or null if there was no mapping for key.
See Also:
PutFromLoadAllOperation

putFromLoad

public Object putFromLoad(Data key,
                          Object value,
                          long ttl)
Description copied from interface: RecordStore
Puts key-value pair to map which is the result of a load from map store operation.

Specified by:
putFromLoad in interface RecordStore
Parameters:
key - key to put.
value - to put.
ttl - time to live seconds.
Returns:
the previous value associated with key, or null if there was no mapping for key.
See Also:
PutAllOperation

tryPut

public boolean tryPut(Data key,
                      Object value,
                      long ttl)
Specified by:
tryPut in interface RecordStore

putIfAbsent

public Object putIfAbsent(Data key,
                          Object value,
                          long ttl)
Specified by:
putIfAbsent in interface RecordStore

loadAllFromStore

public void loadAllFromStore(List<Data> keys,
                             boolean replaceExistingValues)
Description copied from interface: RecordStore
Loads all keys from defined map store.

Specified by:
loadAllFromStore in interface RecordStore
Parameters:
keys - keys to be loaded.
replaceExistingValues - true if need to replace existing values otherwise false

getMapDataStore

public MapDataStore<Data,Object> getMapDataStore()
Specified by:
getMapDataStore in interface RecordStore

getRecordOrNull

public Record getRecordOrNull(Data key)
Description copied from interface: RecordStore
Returns live record or null if record is already expired. Does not load missing keys from a map store.

Specified by:
getRecordOrNull in interface RecordStore
Parameters:
key - key to be accessed
Returns:
live record or null
See Also:
RecordStore.get(com.hazelcast.nio.serialization.Data, boolean)

evictExpiredEntries

public void evictExpiredEntries(int percentage,
                                boolean backup)
Description copied from interface: RecordStore
Do expiration operations.

Parameters:
percentage - of max expirables according to the record store size.
backup - true if a backup partition, otherwise false.

isExpirable

public boolean isExpirable()
Returns:
true if record store has at least one candidate entry for expiration else return false.

resetAccessSequenceNumber

protected void resetAccessSequenceNumber()

evictEntries

public void evictEntries(long now,
                         boolean backup)
TODO make checkEvictable fast by carrying threshold logic to partition. This cleanup adds some latency to write operations. But it sweeps records much better under high write loads.

Parameters:
now - now in time.

postReadCleanUp

protected void postReadCleanUp(long now,
                               boolean backup)
If there is no clean-up caused by puts after some time, try to clean-up from gets.

Parameters:
now - now.

shouldEvict

protected boolean shouldEvict(long now)

markRecordStoreExpirable

protected void markRecordStoreExpirable(long ttl)

getOrNullIfExpired

protected Record getOrNullIfExpired(Record record,
                                    long now,
                                    boolean backup)
Check if record is reachable according to ttl or idle times. If not reachable return null.

Parameters:
record - Record
Returns:
null if evictable.

isExpired

public boolean isExpired(Record record,
                         long now,
                         boolean backup)

accessRecord

protected void accessRecord(Record record,
                            long now)

getName

public String getName()
Specified by:
getName in interface RecordStore

getMapContainer

public MapContainer getMapContainer()
Specified by:
getMapContainer in interface RecordStore

getHeapCost

public long getHeapCost()
Specified by:
getHeapCost in interface RecordStore

getNow

protected long getNow()

createRecord

protected Record createRecord(Data key,
                              Object value,
                              long ttl,
                              long now)

createRecord

protected Record createRecord(Data key,
                              Object value,
                              long now)

accessRecord

protected void accessRecord(Record record)

updateSizeEstimator

protected void updateSizeEstimator(long recordSize)

calculateRecordHeapCost

protected long calculateRecordHeapCost(Record record)

calculateRecordHeapCost

protected long calculateRecordHeapCost(Collection<Record> collection)
Returns total heap cost of collection.

Parameters:
collection - size to be calculated.
Returns:
total size of collection.

resetSizeEstimator

protected void resetSizeEstimator()

updateRecord

protected void updateRecord(Record record,
                            Object value,
                            long now)

getPartitionId

public int getPartitionId()
Specified by:
getPartitionId in interface RecordStore

saveIndex

protected void saveIndex(Record record)

removeIndex

protected void removeIndex(Data key)

removeIndex

protected void removeIndex(Set<Data> keys)

removeIndexByPreservingKeys

protected void removeIndexByPreservingKeys(Set<Data> keysToRemove,
                                           Set<Data> keysToPreserve)
Removes indexes by excluding keysToPreserve.

Parameters:
keysToRemove - remove these keys from index.
keysToPreserve - do not remove these keys.

createLockStore

protected LockStore createLockStore()

onStore

protected void onStore(Record record)

createRecordStoreLoader

protected com.hazelcast.map.impl.RecordStoreLoader createRecordStoreLoader()

clearRecordsMap

protected void clearRecordsMap(Map<Data,Record> excludeRecords)

toData

protected Data toData(Object value)

setSizeEstimator

public void setSizeEstimator(SizeEstimator sizeEstimator)


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.